package com.example.service.impl;

import com.example.mapper.QualityMapper;
import com.example.mapper.TaskMapper;
import com.example.pojo.Order;
import com.example.pojo.PageBean;
import com.example.pojo.Quality;
import com.example.pojo.Task;
import com.example.service.QualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class QualityServiceImpl implements QualityService {

    @Autowired
    private QualityMapper qualityMapper;
    @Autowired
    private TaskMapper taskMapper;

    @Override
    public void add(Quality quality) {
        quality.setInspectionDate(LocalDate.now());
        qualityMapper.add(quality);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, int inspectorID, String result, LocalDate begin, LocalDate end) {
        Long count = qualityMapper.count(inspectorID,result,begin,end);//总数返回
        Integer start=(page-1)*pageSize;//计算起始位置
        List<Quality> qualities = qualityMapper.page(start, pageSize,inspectorID,result,begin,end);//该页记录数返回

        PageBean pageBean = new PageBean(count, qualities);
        return pageBean;
    }

    @Override
    public void delete(int[] id) {
        qualityMapper.delete(id);
    }

    @Override
    public Task selectone(int taskID) {
        return taskMapper.selectone(taskID);
    }
}
